<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 定长子串中元音的最大数目 -->
    <script>
      var maxVowels = function (s, k) {
        const vowels = new Set(['a', 'e', 'i', 'o', 'u'])
        let count = 0,
          l = 0,
          r = 0
        while (r < k) {
          //初始化大小k的窗口
          vowels.has(s[r]) && count++
          r++
        }
        let max = count
        while (r < s.length) {
          //不断移动窗口
          vowels.has(s[r]) && count++
          vowels.has(s[l]) && count--
          l++
          r++
          max = Math.max(max, count) //更新最大元音数
        }
        return max
      }
      console.log(maxVowels('abciiidef', 3))
    </script>
  </body>
</html>
